package com.lcifn.orm.mybatis.manager;

import com.lcifn.orm.mybatis.bean.User;
import com.lcifn.orm.mybatis.mapper.UserMapper;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Repository
public class UserManager {

	@Getter
	@Setter
	@Autowired
	private UserMapper userMapper;

	@Transactional(timeout = 1)
	public void batchOperator(){
		User user = new User("lily", 25);
		int insertRows = userMapper.insert(user);
		try {
			Thread.sleep(3000L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		if(insertRows > 0){
			log.info(user.toString());
			user = userMapper.getUser(user.getId());
			log.info(user.toString());
			userMapper.delete(user.getId()-1);
			// throw new IllegalArgumentException();
		}
	}
}
